#!/usr/bin/env python3 
# -*- coding: UTF-8 -*-

'''
测试百度首页
by lina
'''
from src.gui.page import base_page

class CsdnLogin(base_page.BasePage):

	def __init__(self):
		super().__init__()
		self.index_url = 'https://passport.csdn.net/account/login'


	"""
	进入当前页面
	by lina
	"""
	def in_this_page(self):
		self.mlog.add_log('CsdnLogin','in_this_page','进入csdn登陆页')
		self.mscreenshot.add_screenshot(self.driver,'csdn_login')
		self.driver.get(self.index_url)

	"""
	刷新当前页面
	by lina
	"""
	def refresh_page(self):
		self.mlog.add_log('CsdnLogin','refresh_page','刷新csdn登陆页')
		self.driver.refresh

	"""
	获取登陆方式
	by lina
	"""
	def get_login_method(self):
		self.mlog.add_log('CsdnLogin','get_login_method','获取登陆方式')
		return self.driver.find_element_by_xpath("//a[@class='login-code__open']").text

	"""
	选择账号密码登录方式
	by lina
	"""
	def use_userpwd_login(self):
		self.mlog.add_log('CsdnLogin','use_userpwd_login','选择账号密码登录方式')
		self.driver.find_element_by_xpath("//a[contains(text(),'账号登录')]").click()
		super().delay_time()

	"""
	账号密码登录
	by lina
	"""
	def userpwd_login(self,username,password):
		self.mlog.add_log('CsdnLogin','userpwd_login','账号密码登录')
		self.mlog.add_log('CsdnLogin','userpwd_login','清空账号输入框')
		self.driver.find_element_by_xpath("//input[@id='username']").clear()
		self.mlog.add_log('CsdnLogin','userpwd_login','清空密码输入框')
		self.driver.find_element_by_xpath("//input[@id='password']").clear()
		self.mlog.add_log('CsdnLogin','userpwd_login','输入账号')
		self.driver.find_element_by_xpath("//input[@id='username']").send_keys(username)
		self.mlog.add_log('CsdnLogin','userpwd_login','输入密码')
		self.driver.find_element_by_xpath("//input[@id='password']").send_keys(password)
		self.mscreenshot.add_screenshot(self.driver,'csdn_up_login')
		super().delay_time()
		self.mlog.add_log('CsdnLogin','userpwd_login','点击登陆')
		self.driver.find_element_by_xpath("//input[@class='logging']").click()
		super().delay_time()